from pydantic import BaseModel,validator
import datetime

from tortoise.contrib.pydantic import pydantic_model_creator
from .found_lot_everyday_balance import FoundLotEverydayBalance
from .found_lot_trade_flow import FoundLotTradeFlow

class FoundEverydaySipriceCreate(BaseModel):
    id: int
    base_date:datetime.date
    base_si_price: float = 0
    found_code:str
    found_name:str
    rate:float = 0

class FoundLotEverydayBalanceCreate(BaseModel):
    found_code:str
    found_name:str
    base_date:datetime.date
    holding_shares: float
    holding_si_price: float


class FoundLotEverydayBalanceRead(BaseModel):
    found_code:str
    found_name:str
    base_date:datetime.date
    base_si_price: float
    holding_shares: float
    holding_si_price: float
FoundLotEverydayBalanceRead2 = pydantic_model_creator(FoundLotEverydayBalance)
#指定字段不展示
FoundLotEverydayBalanceRead3 = pydantic_model_creator(FoundLotEverydayBalance,
                        name="FoundLotEverydayBalanceCreate",exclude=("id",'found_code'))


FoundLotTradeFlowRead = pydantic_model_creator(FoundLotTradeFlow,
                        name="FoundLotTradeFlowRead",exclude=("id","trade_si_price",'create_time','update_time')
                                               )
#打印展示的字段
#print(FoundLotTradeFlowRead.schema())

# 自定义 Pydantic 模型，确保 trade_type 被转换为字符串
class FoundLotTradeFlowReadCustom(FoundLotTradeFlowRead):
    # @validator('trade_type', pre=True, always=True)
    # def ensure_str(cls, v):
    #     if isinstance(v, TradeType):
    #         return v.name# 将枚举类型转换为字符串
    #     return v

    class Config:
        orm_mode = True


###########自定义复杂模型
from typing import List
# 请求模型
class POOrderRequest(BaseModel):
    poOrderList: List[str]

# 响应模型
class POAsnDetail(BaseModel):
    poOrderCode: str
    asnOrderNum: str
    volume: float
    weight: float

class POAsnResponse(BaseModel):
    poAsnList: List[POAsnDetail]
